function showGioHoc(ca)
		{	
			if(document.forms[0]["ajaxSwitcher"].value == 0)
				return;
				
			var hStart;
			var hEnd;
			clear = false;
			switch (parseInt(ca))
			{
				case 0:
					hStart = 8;
					hEnd = 22;
					break;
				case 1:
					hStart = 8;
					hEnd = 12;
					break;
				case 2:
					hStart = 13;
					hEnd = 17;
					break;
				case 3:
					hStart = 18;
					hEnd = 22;
					break;
				default:
					clear = true;
			}
			fromHTML = '<select name="f_hstart" id="f_hstart" class="required" onchange="timGiaoVien();">';
			for (i=hStart; i<=hEnd; i++)
			{
				fromHTML += '<option value="'+i+'">'+i+'h</option>';
			}
			fromHTML += '</select>';
			
			endHTML = '<select name="f_hend" id="f_hend" class="required" onchange="timGiaoVien();">';
			for (i=hStart+1; i<=hEnd; i++)
			{
				endHTML += '<option value="'+i+'">'+i+'h</option>';
			}			
			endHTML += '</select>';
			
			if(!clear)
				document.getElementById('showgiohoc').innerHTML = 'Từ ' + fromHTML +' đến '+ endHTML;
			else
				document.getElementById('showgiohoc').innerHTML = '';
		}
		
		function timGiaoVien()
		{
			if(document.forms[0]["ajaxSwitcher"].value == 0)
				return;
			i_ngaybatdau = document.forms[0]["f_ngaybatdau"].value;
			i_tkb = document.forms[0]["f_tkb"].value;
			i_hstart = document.forms[0]["f_hstart"].value; 
			i_hend = document.forms[0]["f_hend"].value;
			i_sobuoi = document.forms[0]["f_sobuoi"].value;
			if (	i_ngaybatdau != ''
				&&	i_tkb != ''
				&&	i_hstart != ''
				&&	i_hend != ''
				&&	i_sobuoi != '') {			
				$.ajax({
				type: 'GET',
				url: 'ajax_timgv.php',
				data: { f_ngaybatdau: i_ngaybatdau,
						f_tkb: i_tkb, 
						f_hstart: i_hstart, 
						f_hend: i_hend, 
						f_sobuoi: i_sobuoi
				},
				async: false,
				success: function(data){
					// document.getElementById('timgv').innerHTML = data;
					selectbox = '<select name="f_giangvien" class="required">';
					selectbox += data;
					selectbox += '</select>';
					document.getElementById('timgv').innerHTML = selectbox;
					
					if(document.forms[0]['showoldgv'] != null) {
						console.log(1);
						reAddOldGV();
					}
				}
				});
			}
		}
		
		function reAddOldGV() {
			selectgv = document.forms[0]["f_giangvien"];
			tengv = document.forms[0]['old_tengiangvien'].value;
			magv = document.forms[0]['old_giangvienid'].value;
			optexist = false;
			console.log(2);
			for (opt in selectgv.options) {
				console.log(3);
				if (opt.value == magv && opt.text == tengv)
				{
					optexist = true;
					console.log(4);
				}
			}
			
			if (!optexist) {
				console.log(5);
				oNgayBatDau = document.forms[0]['old_ngaybatdau'].value;
				oNgayKetThuc = document.forms[0]['old_ngayketthuc'].value;
				oTKB = document.forms[0]['old_tkb'].value;
				oHStart = document.forms[0]['old_hstart'].value;
				oHEnd = document.forms[0]['old_hend'].value;
				oSoBuoi = document.forms[0]['old_sobuoi'].value;
				
				iNgayBatDau = document.forms[0]["f_ngaybatdau"].value;
				iTKB = document.forms[0]["f_tkb"].value;
				iHStart = document.forms[0]["f_hstart"].value; 
				iHEnd = document.forms[0]["f_hend"].value;
				iSoBuoi = document.forms[0]["f_sobuoi"].value;
				
				if (oNgayBatDau == iNgayBatDau &&
					oTKB == iTKB /*&&
					oHStart == iHStart &&
					oHEnd == iHEnd*/
					)
				{
					console.log(6);
					selectgv.options[selectgv.options.length] = new Option(tengv,magv);
					selectgv.options[selectgv.options.length-1].selected = "selected";
				}
			}
		}		
		
		function loadGVFull()
		{
			$.ajax({
				type: 'GET',
				url: 'ajax_loadgvfull.php',
				data: {},
				async: false,
				success: function(data){					
					document.getElementById('timgv').innerHTML = data;
				}
			});
		}
		
		function tinhNgayKetThuc()
		{
			if(document.forms[0]["ajaxSwitcher"].value == 0)
				return;
			i_ngaybatdau = document.forms[0]["f_ngaybatdau"].value;
			i_tkb = document.forms[0]["f_tkb"].value;			
			i_sobuoi = document.forms[0]["f_sobuoi"].value;
			i_hstart =  document.forms[0]["f_hstart"].value;
			i_hend =  document.forms[0]["f_hend"].value;
			f_ngayketthuc = document.forms[0]["f_ngayketthuc"];						
			if (	i_ngaybatdau != ''
				&&	i_tkb != ''
				&&	i_sobuoi != ''
				) {			
				$.ajax({
				type: 'GET',
				url: 'ajax_tinhngayketthuc.php',
				data: { f_ngaybatdau: i_ngaybatdau,
						f_tkb: i_tkb, 
						f_sobuoi: i_sobuoi,
						f_hstart: i_hstart,
						f_hend: i_hend
				},
				async: false,
				success: function(data){
					if (data != '')
						f_ngayketthuc.value = data;
					else
						alert("error");
				}
				});
			}
		}
		
		function toggleAjax(turn)
		{
			var f = document.forms[0]["ajaxSwitcher"];			
			f.value = turn;
		}